<?php
/**
 * Created by PhpStorm.
 * User: sunshine
 * Date: 17-4-18
 * Time: 下午8:41
 */
use Org\Util\GeetestLib;

function GetUserInfo(){
    $returnArr = array();
    $userCookie = cookie('ids');
    if($userCookie){
        $usermodel = new \Admin\Model\UserModel();
        $returnArr = $usermodel->getUserInfoByCookie($userCookie);

    }else{
        $returnArr['status'] = false;
        $returnArr['errcode'] = 100;
        $returnArr['errmsg'] = 'not login';
    }
    return $returnArr;
}
//1注册,2登录,3特别验证 time是第几次验证
function getVerify($type, $time = 0){
    if($type == 1){
        $id = 'c8f88ebf552bb846012816b94ce394eb';
        $key = '4a7378811ecc5d046318247ca1bd5a62';
        $user_id = 'web';
    }elseif ($type == 2){
        $id = 'c8f88ebf552bb846012816b94ce394eb';
        $key = '4a7378811ecc5d046318247ca1bd5a62';
        $user_id = 'web';
    }elseif ($type == 3){
        $id = 'c8f88ebf552bb846012816b94ce394eb';
        $key = '4a7378811ecc5d046318247ca1bd5a62';
        $user_id = 'web';
    }else{
        $id = 'c8f88ebf552bb846012816b94ce394eb';
        $key = '4a7378811ecc5d046318247ca1bd5a62';
        $user_id = 'web';
    }
    if($time == 1){
        $GtSdk = new GeetestLib($id, $key);
        session_start();
        $data = array(
            "user_id" => $_SESSION['user_id'], # 网站用户id
            "client_type" => "web", #web:电脑上的浏览器；h5:手机上的浏览器，包括移动应用内完全内置的web_view；native：通过原生SDK植入APP应用的方式
            "ip_address" => $_SERVER['REMOTE_ADDR'] # 请在此处传输用户请求验证时所携带的IP
        );
        $status = $GtSdk->pre_process($data, 1);
        $_SESSION['gtserver'] = $status;
        $_SESSION['user_id'] = $user_id;
        return $GtSdk->get_response_str();
    }else{
        session_start();
        $data = array(
            "user_id" => $_SESSION['user_id'], # 网站用户id
            "client_type" => "web", #web:电脑上的浏览器；h5:手机上的浏览器，包括移动应用内完全内置的web_view；native：通过原生SDK植入APP应用的方式
            "ip_address" => $_SERVER['REMOTE_ADDR'] # 请在此处传输用户请求验证时所携带的IP
        );
        $GtSdk = new GeetestLib($id, $key);
        if ($_SESSION['gtserver'] == 1) {   //服务器正常
            return $GtSdk->success_validate($_POST['geetest_challenge'], $_POST['geetest_validate'], $_POST['geetest_seccode'], $data);
        }else{  //服务器宕机,走failback模式
            return $GtSdk->fail_validate($_POST['geetest_challenge'],$_POST['geetest_validate'],$_POST['geetest_seccode']);

        }
    }

}